Skip to content

Array pack with format J and j specs - #320

Merged
eregon merged 5 commits into
ruby:masterfrom
mjago:pack_array_with_format_J
Oct 20, 2016
Merged

eregon merged 5 commits into
ruby:masterfrom
mjago:pack_array_with_format_J

Conversation

@mjago

@mjago mjago commented Oct 19, 2016

Copy link
Copy Markdown
Contributor

Add specs for Array pack j and J directives for pointer width integer type.

Issue Ruby 2.3 specs #175 - Feature #11215

@mjago

mjago commented Oct 19, 2016

Copy link
Copy Markdown
Contributor Author

I'm putting these specs out there as I need guidance regarding the use of standard libraries, and a custom guard (pointer_size_is).
Am I free to require Fiddle (to access Fiddle::SIZEOF_INTPTR_T) from a spec file?
Fiddle is in the standard library. I'm anticipating here that there are cases where pointer width differs from integer width (MRuby?).
Also, should the guard go somewhere else?
Thanks!

@eregon

eregon commented Oct 20, 2016

Copy link
Copy Markdown
Member

It would be better to not require Fiddle (stdlib) in core specs if we can avoid it.

There is already a similar guard: platform_is wordsize: 64 do for example in https://github.com/ruby/spec/blob/master/core/array/pack/l_spec.rb#L32.
It's currently implemented using Fixnum#size, but this could of course be fixed for mruby when needs be.
I think it's safe to assume word size == pointer size, what do you think?

@eregon

eregon commented Oct 20, 2016

Copy link
Copy Markdown
Member

There is currently an issue with mingw32-compiled ruby on Windows 64-bit, where technically the platform is 64-bit but it behaves much more similar to a 32-bit one due to the compiler toolchain. I need to figure that one out, but you should not need to worry about this special case here.

@mjago

mjago commented Oct 20, 2016

Copy link
Copy Markdown
Contributor Author

Another way I thought of finding pointer width was ([255].pack('J')).length but that kind of defeats the object I guess.

I'll remove Fiddle dependency and use wordsize guard.

Thanks!

mjago added 2 commits October 20, 2016 11:16
in Array pack with format J and j specs
to pack array with format J
@mjago

mjago commented Oct 20, 2016

Copy link
Copy Markdown
Contributor Author

I added mingw32 guards as per l_spec. Thanks for the heads-up!

Comment thread core/array/pack/j_spec.rb Outdated

platform_is_not :mingw32 do

describe "Array#pack with modifier '_'" do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you nest the describe calls like in https://github.com/ruby/spec/blob/master/core/array/pack/l_spec.rb#L23-L24 ?
So the full description for those specs still mention 'J' 😄

Comment thread core/array/pack/j_spec.rb Outdated
require File.expand_path('../shared/integer', __FILE__)

ruby_version_is '2.3' do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the extra vertical space when there is already an indentation change?

@eregon

eregon commented Oct 20, 2016

Copy link
Copy Markdown
Member

Another way I thought of finding pointer width was ([255].pack('J')).length but that kind of defeats the object I guess.

Yes indeed, it would only test that it's consistent with itself.

Comment thread core/array/pack/j_spec.rb Outdated
end

describe "Array#pack with format 'j'" do
describe "Array#pack with modifier '_'" do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing: the Array#pack here is redundant.
You can have a look at the final description with mspec -fs path/to/spec.rb

@eregon
eregon merged commit 5ec5a10 into ruby:master Oct 20, 2016
@eregon

eregon commented Oct 20, 2016

Copy link
Copy Markdown
Member

That's perfect, thanks a lot for the new spec and the fixes! 👍 🎉

@mjago
mjago deleted the pack_array_with_format_J branch October 20, 2016 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants